<?php
namespace app\index\Controller;
use think\Controller;
use app\index\model\House as Hou;
use app\index\controller\commom;
class House extends Common
{
	public function index()
	{
		return view('list');
	}
	public function list()
	{
		$hou = new Hou();
		$list = $hou->list();
		return view("list",["list"=>$list]);
	}
	
	public function add(){
        $hou = new Hou();
        if(input("?param.sub")){
            $file = request()->file('image');
            if($file){
                $result = $hou->adds($file);
            }
            else{
                $result = $hou->add();
            }
            if($result){
                $this->success("添加成功","house/list");
            }else{
                $this->error("添加失败");
            }
        }
        else{
            return view("add",[]);
        }
    }
	public function adds($file){
        $info = $file->move( './uploads');
        $infoname=$info->getfilename();
        $data=[
            'name'=>input("param.name"),
            'h_name'=>input("param.h_name"),
			'h_type'=>input("param.h_type"),
			'area'=>input("param.area"),
			'phone'=>input("param.phone"),
			'money'=>input("param.money"),
			'payment'=>input("param.payment"),
			'z_money'=>input("param.z_money"),
			'user_id'=>input("param.user_id"),
            'image'=>$infoname,
        ];
        $hou = new House();
        $result = $hou->save($data);
        return $result;
    }
	public function update()
    {
        $hou = new Hou();
        $result = $hou->dan();
        if(input("?param.subm")) {
            $resultt= $hou
                ->updateById();
            if($resultt){
                $this->success("修改成功","house/list");
            }else{
                $this->error("修改失败");
            }
        }
        else {
            return view('update', ['list' => $result]);
        }
    }
	public function delete(){
        $id = input("param.id");
        $hou = new Hou();
        $result = $hou->deleteById($id);
        if($result){

            $this->success("删除成功","house/list");
        }else{
            $this->error("删除失败");
        }
    }
}
?>